/*
 * Created on Jul 28, 2004
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package com.ba360.struts.form;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;

import com.ba360.portal.common.PortalConstants;
import com.ba360.portal.database.dbo.User;

/**
 * @author ROnat
 * 
 * TODO To change the template for this generated type comment go to Window -
 * Preferences - Java - Code Style - Code Templates
 */
public class ResponseForm extends ActionForm {

	private String respEmail;

	private String respMessage;
	private String adId;
	private String adTitle;

	public void setAdId(String adId) {
		this.adId = adId;
	}

	public String getAdId() {
		return adId;
	}
	public void setAdTitle(String adTitle) {
		this.adTitle = adTitle;
	}

	public String getAdTitle() {
		return adTitle;
	}
	
	public void setRespEmail(String respEmail) {
		this.respEmail = respEmail;
	}

	public String getRespEmail() {
		return respEmail;
	}

	public void setRespMessage(String respMessage) {

		this.respMessage = respMessage;
	}

	public String getRespMessage() {
		return respMessage;
	}

	public ActionErrors validate(ActionMapping mapping,
			HttpServletRequest request) {
		ActionErrors ae = new ActionErrors();
		if (request.getParameter(PortalConstants.ACTION) != null) {
			if (respEmail == null || respEmail.equals("")) {
				ae.add("Email Address", new ActionError("error.email.value"));

			}
			if (respEmail.indexOf("@") == -1 || respEmail.indexOf(".") == -1
					|| respEmail.length() < 8)
				ae.add("Email", new ActionError("error.invalidemail.value"));
			if (respMessage == null || respMessage.equals("")) {
				ae.add("Response Message", new ActionError(
						"error.respmessage.value"));

			}
		}
		User user = (User)request.getSession().getAttribute(PortalConstants.USER);
		if (user!=null)
		{
			respEmail = user.getEmail();
		}
		return ae;
	}

	public void reset(ActionMapping mapping, HttpServletRequest request) {

	}
}